package com.example.j2025_11_9;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/User")
public class User {
    @RequestMapping("/login")
    public Boolean login(String name, String password, HttpSession session) {
        if (!StringUtils.hasLength(name) || !StringUtils.hasLength(password)) {
            return false;
        }
        if ("User".equals(name) && "User".equals(password)) {
            session.setAttribute("User", name);
            return true;
        }
        return false;
    }

    @RequestMapping("/getname")
    public String getname(HttpSession session) {
        String name = (String) session.getAttribute("User");
        return name;
    }
}
